package com.shketai.service;

import java.util.ArrayList;
import java.util.List;

import com.shketai.dao.ImessageDao;
import com.shketai.dao.UserDao;
import com.shketai.entity.Imessage;
import com.shketai.entity.PageBean;

public class ImessageService {

	private ImessageDao imessageDao;
	
	private UserDao userDao;

	public void setImessageDao(ImessageDao imessageDao) {
		this.imessageDao = imessageDao;
	}
	
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	public void add(String head,String message,int teacher_id){
		List<Integer> user_ids = userDao.findAllIds();
		imessageDao.add(user_ids, head, message, teacher_id);
	}
	
	public PageBean<Imessage> find(int user_id,int page){
		PageBean<Imessage> pb = new PageBean<Imessage>();
		List<Imessage> list = imessageDao.find(user_id,page);
		pb.setDatas(list);
		int total = imessageDao.findCount1(user_id);
		pb.setTotal(total);
		return pb;
	}
	
	public void updateFlag(int id){
		imessageDao.updateFlag(id);
	}
	
	public Imessage findById(int id) {
		Imessage imessage = imessageDao.findById(id);
		return imessage;
	}
	
	public int delete(Imessage imessage){
		int result = imessageDao.delete(imessage);
		return result;
	}

	public int count(int user_id){
		int result = imessageDao.findCount(user_id);
		return result;
	}
}
